<?php
$message = '';
$db = new mysqli('localhost', 'root', 'root', 'rashidStone');
if($db->connect_error) {
  $message = $db->connect_error;
} else {
  $sql = 'SELECT User.FirstName, User.UserID, User.SchoolYear, User.State,  User.LastName, Class.Name FROM User LEFT JOIN Class ON Class.ClassID = User.ClassID';
  $result = $db->query($sql);
  $tagsql = 'SELECT Tag.Name, Tag.TagID FROM Tag';
  $tagresult = $db->query($tagsql);
  if($db->error) {
    $message = $db->error;
  }
}
?>

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
  <meta charset="UTF-8">
  <title>Tag Student</title>
  <link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Rashid Stone</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Manage Students <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="addStudent.html">Add Student</a></li>
            <li><a href="enroll.php">Enroll Student</a></li>
          </ul>
        </li>
          <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Manage Tags <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="addTag.html">Add Tag</a></li>
            <li class="active"><a href="tagStudent.php">Tag Student</a></li>
          </ul>
        </li>
        <li><a href="addClass.html">Add Class</a></li>
        <li>
       <a href="viewStudents.php"> View Students</a>
        </li>
                      <li>
       <a href="viewTags.php"> View Tags</a>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

<div class="container">
<?php if ($message) {
    echo "<h2>$message</h2>";
  } else {
    ?>
    <form action="tagToStudent.php" method="post">
    Tag Name:
      <select class="form-control" name="tag">
        <?php while ($tag = $tagresult->fetch_assoc()) {?>
  
        <option value="<?php echo $tag['TagID']?>"> <?php echo $tag['Name']?> </option>
        <?php } ?> 
      </select>
      <table class="table table-hover">
      <thead>
          <th>#</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>School Year</th>
          <th>Class Name</th>
        
      </thead>
        <?php while ($row = $result->fetch_assoc()) { ?>
  <tbody>
    
            <tr style="cursor:pointer">
              <td><input type="checkbox" name="user[]" value="<?php echo $row['UserID'] ?> "></td>
              <td><?php echo $row['FirstName']?></td>
              <td><?php echo $row['LastName']?></td>
              <td><?php echo $row['SchoolYear']?></td>
              <td><?php echo $row['Name']?></td>
      
            </tr>
  </tbody>
        <?php } //end of loop ?>
      </table>
      <input class="btn btn-default" type="submit">
  
    </form>
    <?php } //end of page ?></div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/script.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
  </html>
